package ru.bragnikita.utils.swing.widget;

import ru.bragnikita.utils.swing.utils.ValueUtils;

import javax.swing.*;

/**
 * @author Nikita.Brazhnikov
 */
public abstract class WtAbstractTextWidget<T extends JComponent> implements WtTextWidget<T>{

    private T component;
    private String id;
    private JLabel label;

    protected WtAbstractTextWidget(String id) {
        this.id = id;
    }

    protected final void setComponent(T component) {
        this.component = component;
    }

    protected final void setLabel(JLabel label) {
        this.label = label;
    }

    @Override
    public T getComponent() {
        return component;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public JLabel getLabel() {
        return label;
    }

	@Override
	public void setValue(String param, Object value) {
		switch (param) {
			case "value": setValue(value);
				break;
			case "enabled":
				getComponent().setEnabled(ValueUtils.getBoolean(value));
				break;
			default:
		}
		setProperty(param,value);
	}

	protected void setProperty(String param, Object value){}
}
